<template>
  <div class="page-search">
    <HyForm v-bind="searchFormConfig" v-model="originData">
      <template #header>
        <h1 class="header">高级检索</h1>
      </template>
      <template #footer>
        <div class="handle-btns">
          <el-button :icon="Refresh" @click="handleResetClick">重置</el-button>
          <el-button type="primary" :icon="Search" @click="handleQueryClick"
            >搜索</el-button
          >
        </div>
      </template>
    </HyForm>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue"
import HyForm from "@/base-ui/form"
import { Search, Refresh } from "@element-plus/icons-vue"
export default defineComponent({
  props: {
    searchFormConfig: {
      type: Object,
      default: () => ({})
    }
  },
  components: {
    HyForm
  },
  emits: ["resetBtnClick", "queryBtnClick"],
  setup(props, { emit }) {
    // 初始化v-model
    const formItems = props.searchFormConfig?.formItems ?? []
    const formOriginData: any = {}
    for (const iterator of formItems) {
      formOriginData[iterator.field] = ""
    }
    const originData = ref(formOriginData)
    //重置
    const handleResetClick = () => {
      originData.value = formOriginData
      emit("resetBtnClick", originData.value)
    }
    // 搜索
    const handleQueryClick = () => {
      console.log(originData.value)
      emit("queryBtnClick", originData.value)
    }
    return { originData, handleResetClick, handleQueryClick, Search, Refresh }
  }
})
</script>

<style lang="less"></style>
